﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Services;
using Domain = Sunboxsoft.ASMS.Server.Domain;
using Entity = Sunboxsoft.ASMS.Server.Domain.Entity;
using View = Sunboxsoft.ASMS.Server.Domain.View;
using Data = Sunboxsoft.ASMS.Server.Domain.Data;
using Service = Sunboxsoft.ASMS.Server.Domain.Service;
using Sunboxsoft.Common;

namespace Sunboxsoft.ASMS.Web.Services
{
    /// <summary>
    /// BasesWebService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务，请取消注释以下行。 
    // [System.Web.Script.Services.ScriptService]
    public class BasesWebService : System.Web.Services.WebService
    {
        [WebMethod]
        public SingleResult<Models.Account> Login(string identity, string password)
        {
            SingleResult<Entity.EStaff> result = new Service.GetService().GetStaffByAccount(identity);
            if (result.IsSuccess)
            {
                string md5Password = Common.Utility.MD5Utility.GetStringX(password);
                if (string.Equals(md5Password, result.Data.Password))
                {
                    Models.Account account = new Models.Account();
                    account.Id = result.Data.Id;
                    account.Name = result.Data.Name;

                    Sunboxsoft.ASMS.WebUtility.CookieUtility.SetUserId(account.Id, account.Name);

                    return new SingleResult<Models.Account>(account);
                }
                return new SingleResult<Models.Account>(0, "账号密码错误");
            }

            return new SingleResult<Models.Account>(0, result.Message);
        }

        [WebMethod]
        public SingleResult<Models.VIPCustomer> CheckVIP(string telephone)
        {
            Integration.User user = Integration.MobileRechargeServiceProxy.ValidateCustomer(telephone);
            if (user != null)
            {
                Models.VIPCustomer vip = new Models.VIPCustomer();
                vip.IdNumber = user.IdCode;
                vip.Name = user.UserName;
                vip.VIPNumber = user.AcctId;
                vip.UniqueId = user.IdCode;
                vip.EMail = user.EMail;
                vip.BirthDay = user.BirthDay;
                vip.GradeId = user.GradeId;
                vip.GradeCode = user.GradeCode;
                vip.GradeName = user.GradeName;
                vip.GradeIcon = user.GradeIcon;
                return new SingleResult<Models.VIPCustomer>(vip);
            }
            else
            {
                return new SingleResult<Models.VIPCustomer>(1, "vip not exist");
            }
        }
    }
}
